<?php
/**
 *   Joomdiet - administrator/components/controllers/recipecategories.php
 *   Author: Juan Dapena Paz (juan@bittingbits.com)
 *   Copyright (C) 2010 Bitting Bits S.L.
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.controller');

class JoomdietControllerRecipeCategories extends JController
{
    function __construct()
    {
        // get requested view
        if (JRequest::getCmd('view') == '') {
            JRequest::setVar('view', 'default');
        }
        
        $this->item_type = 'Default';
        parent::__construct();
        
        $this->registerTask('addRecipeCategory', 'editRecipeCategory');
    }
    
    function editRecipeCategory()
    {
        JRequest::setVar('view', 'recipeCategory');
        JRequest::setVar('hidemainmenu', 1);
        
        $model = $this->getModel('recipecategory');
        $user =& JFactory::getUser();
        
        parent::display();
    }
    
    function save()
    {
        $model = $this->getModel('recipecategory');
        
        if ($model->store()) {
            $msg = JText::_('COM_JOOMDIET_RECIPE_CATEGORY_SAVE');
        } else {
            $msg = JText::_('COM_JOOMDIET_RECIPE_CATEGORY_ERROR_SAVE');
        }
        
        $link = 'index.php?option=com_joomdiet&view=recipecategories';
        $this->setRedirect($link, $msg);
    }
    
    function deleteRecipeCategory()
    {
        $model =& $this->getModel('RecipeCategories');
        $cid = JRequest::getVar('cid', array(0), 'post', 'array');
        foreach ($cid as $id)
            $model->deleteNodeByIds($id);
    }
    
    function directDeleteRecipeCategory()
    {
        $model =& $this->getModel('RecipeCategories');
        $cid = JRequest::getVar('cid', array(0), 'request', 'array');
        foreach ($cid as $id)
            $model->deleteNodeByIds($id);
    }
}
?>
